package com.lzh.chatnote.user.service.event.listener;

import com.lzh.chatnote.common.mqConsumer.IdempotentEnum;
import com.lzh.chatnote.common.mqConsumer.ItemEnum;
import com.lzh.chatnote.user.domain.entity.User;
import com.lzh.chatnote.user.service.UserBackpackService;
import com.lzh.chatnote.user.service.event.UserRegisterEvent;
import lombok.extern.slf4j.Slf4j;
import org.springframework.context.event.EventListener;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;

@Slf4j
@Component
public class UserRegisterListener {

    @Resource
    private UserBackpackService iUserBackpackService;

    @Async
    @EventListener(classes = UserRegisterEvent.class)
    public void sendCard(UserRegisterEvent event) {
        User user = event.getUser();
        //送一张改名卡
        iUserBackpackService.acquireItem(user.getId(), ItemEnum.MODIFY_NAME_CARD.getId(), IdempotentEnum.UID, user.getId().toString());
    }
}
